/*
 * @Descripttion: 
 * @version: 
 * @Author: lily
 * @Date: 2021-03-28 17:39:58
 * @LastEditors: lily
 * @LastEditTime: 2021-05-11 14:28:02
 */
/*
 * @lc app=leetcode.cn id=118 lang=javascript
 *
 * [118] 杨辉三角
 */

// @lc code=start
/**
 * @param {number} numRows
 * @return {number[][]}
 */
//  思路：
//  把每行初始值设定好 其他值由上一行进行计算
//  复杂度：O(n2) O(1)
var generate = function (numRows) {
    let res = [[1]]
    for (let i = 1; i < numRows; i++) {
        let curr = []
        for (let j = 0; j < i + 1; j++) {
            if (j === 0 || j === i) {
                curr.push(1)
            } else {
                curr.push(res[i - 1][j - 1] + res[i - 1][j])
            }
        }
        res.push(curr)
    }
    return res
};
// @lc code=end

console.log(generate(5));
